
<template>
  <div class="execution">
    <basic-container>
      <avue-crud
        ref="crud"
        :page.sync="page"
        :data="tableData"
        :table-loading="tableLoading"
        :option="tableOption"
        @on-load="getList"
        @search-change="searchChange"
        @refresh-change="refreshChange"
        @row-del="rowDel">
        <template slot="menuLeft" slot-scope="scope">
          <el-button
            type="primary"
            size="small"
            icon="el-icon-plus
          "
            @click="jumpToAdd(scope.row)">新增</el-button>
        </template>
        <template slot-scope="scope" slot="menu">
          <el-button
            type="text"
            icon="el-icon-view"
            size="small"
            plain
            @click="jumpToDetail(scope.row)">详情</el-button>
          <el-button
            type="text"
            icon="el-icon-edit"
            size="mini"
            @click="jumpToEdit(scope.row)">编辑</el-button>
          
        </template>
      </avue-crud>
    </basic-container>
  </div>
</template>

<script>
import { fetchList, delObj } from '@/api/crm/salesorder'
import { tableOption } from '@/const/crud/supply/supplyorder'
export default {
  name: 'salesorder',
  data() {
    return {
      tableData: [],
      page: {
        total: 0, // 总页数
        currentPage: 1, // 当前页数
        pageSize: 20 // 每页显示多少条
      },
      // 表格加载状态
      tableLoading: false,
      // 表格配置
      tableOption: tableOption
    }
  },
  methods: {
    getList(page, params) {
      this.tableLoading = true
      fetchList(Object.assign({
        current: page.currentPage,
        size: page.pageSize
      }, params)).then(response => {
        this.tableData = response.data.data.records
        this.page.total = response.data.data.total
        this.tableLoading = false
      })
    },
    rowDel(row, index) {
      this.$confirm('是否确认删除该订单', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function() {
        return delObj(row.id)
      }).then(data => {
        this.tableData.splice(index, 1)
        this.$message({
          showClose: true,
          message: '删除成功',
          type: 'success'
        })
        this.getList(this.page)
      }).catch(function(err) {
      })
    },
    /**
       * 搜索回调
       */
    searchChange(form, done) {
      this.getList(this.page, form)
      done()
    },
    /**
       * 刷新回调
       */
    refreshChange(info) {
      this.getList(this.page, this.filterForm(info.searchForm))
    },
    jumpToDetail(row) {
      this.$router.push({ path: 'detailsupplyorder', query: row })
    },
    jumpToEdit(row) {
      this.$router.push({ path: 'editsupplyorder', query: row })
    },
    jumpToReview(row) {
      const query = { res: {
        salesOrderSn: row.salesOrderSn
      }}
      this.$router.push({ path: '/orderCon/salesOrderReview', query: query })
    },
    jumpToAdd(row) {
      this.$router.push({ path: 'addsupplyorder', query: row })
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
